package com.bianmaba.oauth2.controller.security.resource;

import com.bianmaba.oauth2.bean.entity.Resource;
import com.bianmaba.oauth2.service.security.resource.IResourceService;
import com.bianmaba.spring.supports.data.beans.basc.PabeableRequest;
import com.bianmaba.spring.supports.mvc.annotations.EntityParam;
import com.bianmaba.spring.supports.mvc.annotations.JSON;
import com.bianmaba.spring.supports.mvc.annotations.MapParam;
import com.bianmaba.spring.supports.mvc.controller.CrudController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;

/**
 * Created by cwx183898 on 2017/8/10.
 */
@RestController
@RequestMapping(value = {"management/security/resource"})
public class MGTResourceController extends CrudController<Resource, String> {

    @Autowired
    private IResourceService service;

    @Override
    protected IResourceService getService() {
        return service;
    }

    @JSON(excludeProperties = "data.*\\.users\\.resources,data.*\\.roles\\.resources")
    public Resource save(@EntityParam Resource entity) {
        return super.save(entity);
    }

    @Override
    @JSON(excludeProperties = "data.*\\.roles\\.resources,data.*\\.roles\\.users")
    public Resource getById(String id) {
        return super.getById(id);
    }

    @JSON(excludeProperties = "data.*\\.roles")
    public Page<Resource> query(@MapParam LinkedHashMap<String, Object> params, @EntityParam PabeableRequest pageable) {
        return super.query(params, pageable);
    }
}
